<template>
  <div>
    <h1 align="center">注册</h1>
    <table align="center" class="table table-bordered">
      <tr>
        <td align="center">用户名：</td>
        <td><input type="text" align="center" v-model="state.username" /></td>
      </tr>
      <tr>
        <td align="center">密码</td>
        <td>
          <input type="password" align="center" v-model="state.password" />
        </td>
      </tr>
      <tr>
        <td colspan="2" align="center">
          <input type="button" value="注册" @click="login" />
        </td>
      </tr>
    </table>
  </div>
</template>

<script setup lang="ts">
import { reactive, toRefs } from 'vue';
import axios from 'axios';
import { useRouter } from 'vue-router';
const router = useRouter();
//数据
let data = reactive({
  state: {
    username: '',
    password: ''
  }
});
let { state } = toRefs(data);
//函数
const login = () => {
  //1.非空+有效性
  //2.发送请求
  let obj = {
    id: 0,
    ureadWord: state.value.username,
    passWord: state.value.password
  };
  axios({
    url: 'https://localhost:7157/api/JIUmemeelr/ZHUCE',
    method: 'post',
    data: obj
  })
    .then((res) => {
      console.log(res);
      if (res.data > 0) {
        alert('注册成功');
        router.push('/register');
      }
      else{
        alert('注册失败');
      }
      if (res.data == -2) {
        alert('用户已存在');
        router.push('/');
      }
    })
    .then((err) => {
      console.log(err);
    });
};
</script>

<style scoped></style>
